package Rbac.view;

import java.util.Scanner;

public class MainView {
    public static final String MENU = """
            --------------------
                   RBAC系统
            |     0:退出系统     |
            |     1:部门管理     |
            |     2:角色管理     |
            |     3:用户管理     |
            --------------------
            """;
    public static Scanner input;
    private static MainView singleton;

    static {
        input = new Scanner(System.in);
    }

    private final DeptView deptView;
    private final RoleView roleView;
    private final UsersView usersView;

    private MainView() {
        deptView = DeptView.getInstance();
        roleView = RoleView.getInstance();
        usersView = UsersView.getInstance();
    }

    public static MainView getInstance() {
        if (singleton == null) {
            singleton = new MainView();
        }
        return singleton;
    }

    /**
     * 显示主页面
     */
    public void showMenu() {
        String menuChoice;
        do {
            System.out.println(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统， 欢迎下次使用！");
                case "1" -> deptView.showMenu();
                case "2" -> roleView.showMenu();
                case "3" -> usersView.showMenu();
                default -> System.out.println("输入有误，请输入正确菜单编号！");
            }
        } while (!"0".equals(menuChoice));
        input.close();
    }
}
